<?php
/**
 * @package SLURP
 * @subpackage Dataobjects
 */
class slurp_user extends Lead_EDO_Object_Basic
{
	static $_typeid = 2;
	static $_tables = array('slurp_users');
	
	
	static $_extended_datatypes = array
	(
	'email' => 'email',
	'pwd' => 'password',
	// 'groups' => 'relation_manytomany',
	);
	
	static $_relations = array
	(
	   array(
	   'name' => 'groups',
	   'type' => 'relation_has_and_belongs_to_many',
	   'class_name' => 'slurp_group',
	   'foreign_key' => 'users',
	   'join_table' => 'slurp_group_users_slurp_user_groups',
	   ),

	);
	
	
	
	protected $groups;
	
	
	public function __construct(Lead_EDO_Handler_Interface $edo_handler)
	{
		parent::__construct($edo_handler);
	}
	
	
	function getGroups()
	{
		return $this->getFieldObject('groups')->getValueArray();
		
	}

	
	
	function inGroup()
	{
	   
	   foreach(func_get_args() as $gid)
	   {
	       if(in_array($gid, $this->getField('groups')->getKeys()))
	           return true;
	   }
	   
	   return false;
	    
	    
	}
	
	
	
	public function isAnonymous()
	{
		return $this->inGroup(-1);
	}
	
	public function isRoot()
	{
		return $this->inGroup(-2);
	}
	

}
?>